// components/payment-code/payment-code.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title: {
      type: String,
      value: '请输入支付密码'
    },
    validate: { // 忘记密码
      type: Boolean,
      value: true
    },
    price:{
      type:null,
      value:''
    }
  },
  data: {
    focus: true,
    code: '',
    isErr: true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    no(){},
    input(e) {
      const that = this;
      const val = e.detail.value;
      that.setData({
        code: val
      })
      if (that.properties.validate) {
        if (val.length === 6) that.submit()
      } else {
        if (val.length > 1) {
          const mark = validate(val);
          that.setData({
            isErr: mark
          })
        }

        if (val.length === 6) {
          const mark = validate(val);
          that.setData({
            isErr: mark
          })
          if (mark) {
            that.submit()
          }
        }
      }

    },

    focusHandler() {
      this.setData({
        focus: true
      })
    },
    find(){
    
      this.triggerEvent('find') 
    },
    submit() {
      // 派发事件
      this.triggerEvent('submit', { code: this.data.code })
    },
    none(){
      this.triggerEvent('none')
    }

  }
})


